package xmldatabase;

import java.sql.*;

//输入一个ID
//如果该ID信息存在，则显示出该ID对应的密码和权限
public class Login {

    // 连接对象
    private Connection conn;
    // 传递sql语句
    private Statement stt;
    // 结果集
    private ResultSet set;

    public String password;
    public String position;

    ResultSet rs;
    // 查询
    Statement stmt = null;

    public void auth(String x) {

        try {
            conn = DBConnection.getConnection();
            if (conn == null) {
                return;
            }
         
            String sql = "select * from news where id=' " + x + " ' ";
            stt = conn.createStatement();
            rs = stt.executeQuery(sql);

            while (rs.next()) {
                password = rs.getString("password");
                position = rs.getString("position");
                System.out.println(password);
                System.out.println(position);
            }

        } catch (Exception ex) {

            System.out.println(ex.toString());

        } finally {
            if (stt != null) {
                try {
                    stt.close();
                } catch (Exception ex) {
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (Exception ex) {
                }
            }
        }
        System.out.println("End");
    }
}
